@echo off
REM **************************************************
REM Sharepoint Discoverter Build Script
REM http://www.codeplex.com/discoverter/
REM http://www.Stum.de
REM **************************************************
REM $Id$
REM **************************************************

SET PATH=%PATH%;F:\builds\tools
f:
cd \builds
rd /S /Q discoverter_build
rd /S /Q discoverter_source

IF /I "%1"=="" (
  set repopath=/trunk
  set revparam=
  set rarext=-daily
  set rarparam=-ag"-YYYY-MM-DD"
  set dohash=
) ELSE (
  set repopath=/tags/%1
  set revparam=/t /v %1
  set rarext=-%1
  set rarparam=
  set dohash=yes
)

svn co https://discoverter.svn.codeplex.com/svn%repopath% discoverter_source
cd \builds\discoverter_source
cmdnetsvnrev /c . /r https://discoverter.svn.codeplex.com/svn%repopath% %revparam%

REM *** Delete all .svn folders and package up source
for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *.svn') do ( rd /S /Q "%%i" )
rar a %rarparam% -vn -av -dh -k -m5 -os -r -s -t f:\builds\discoverter\discoverter-src%rarext%.rar .

REM *** Build the project and package up binaries
C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe /p:Configuration=Release /p:OutputPath=f:\builds\discoverter_build discoverter/discoverter.csproj
C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe /p:Configuration=Release /p:OutputPath=f:\builds\discoverter_build DiscoverterWin/DiscoverterWin.csproj
copy ReadMe.txt f:\builds\discoverter_build
copy LICENSE.txt f:\builds\discoverter_build
cd \builds\discoverter_build
rar a %rarparam% -vn -av -dh -k -m5 -os -r -s -t f:\builds\discoverter\discoverter%rarext%.rar .

IF /I "%dohash%"=="yes" (
cd \builds\discoverter
cmdhashgen.exe /a /b discoverter-src%rarext%.rar >discoverter-hash%rarext%.txt
cmdhashgen.exe /a /b discoverter%rarext%.rar >>discoverter-hash%rarext%.txt
)

cd \builds
rd /S /Q discoverter_build
rd /S /Q discoverter_source